package string;

/**
 * String支持正则表达式三
 * String replaceAll(String regex,String str)
 * 将当前字符串中满足正则表达式的部分替换为给定内容
 */
public class ReplaceAllDemo {
    public static void main(String[] args) {
        String str="abc123def456ghi";
        //将数字部分替换为 #NUMBER#
        str=str.replaceAll("[0-9]+","#NUMBER#");
        System.out.println(str);

        str="abc123def456ghi789jiu";
        str=str.replaceAll("[0-9]","#NUMBER#");
        System.out.println(str);

         str="abc123def456ghi";
        str=str.replaceAll("[a-z]+","#NUMBER#");
        System.out.println(str);

        str="abc123def456ghi789jiu";
        str=str.replaceAll("[a-z]","#NUMBER#");
        System.out.print(str);
        System.out.println();


            //和谐用语
        String regex="(wqnmlgb|dsb|mdzz|nmsl|wrsndm|cnm|nc|djb)";
        String message="wqnmlgb!你个dsb!你怎么这么的nc,你就是个djb!";
        message=message.replaceAll( regex,"***");
        System.out.println(message);

    }
}
